OCAMLC=ocamlc
OCAMLOPT=ocamlopt
OCAMLDEP=ocamldep
OCAMLLEX=ocamllex
OCAMLYACC=ocamlyacc
INCLUDES=                 # all relevant -I options here
OCAMLFLAGS=$(INCLUDES)    # add other options for ocamlc here
OCAMLOPTFLAGS=$(INCLUDES) # add other options for ocamlopt here

PRINTOBJS=ast.cmo errors.ml parseutils.cmo types.cmo lexer.cmo parser.cmo\
 parsemp.cmo run.cmo print.cmo

PRINTIOBJS=ast.cmo errors.ml parseutils.cmo types.cmo lexer.cmo parser.cmo\
 parsemp.cmo env.cmo icode.cmo gen.cmo frame.cmo icodegen.cmo run.cmo printi.cmo

PCOMPOBJS=ast.cmo errors.ml parseutils.cmo types.cmo lexer.cmo parser.cmo\
 parsemp.cmo env.cmo icode.cmo gen.cmo frame.cmo icodegen.cmo pcodegen.cmo run.cmo pcomp.cmo


EXECUTABLES= print printi pcomp

all:
	make pcomp
	make printi
	make print

pcomp: $(PCOMPOBJS) 
	$(OCAMLC) $(OCAMLFLAGS) -o pcomp $(PCOMPOBJS)

printi: $(PRINTIOBJS) 
	$(OCAMLC) $(OCAMLFLAGS) -o printi $(PRINTIOBJS) 

print: $(PRINTOBJS) 
	$(OCAMLC) $(OCAMLFLAGS) -o print $(PRINTOBJS)

# Common rules
.SUFFIXES: .ml .mli .cmo .cmi .cmx .mll .mly

.ml.cmo:
	$(OCAMLC) $(OCAMLFLAGS) -c $<

.mli.cmi:
	$(OCAMLC) $(OCAMLFLAGS) -c $<

.ml.cmx:
	$(OCAMLOPT) $(OCAMLOPTFLAGS) -c $<

.mll.ml:
	$(OCAMLLEX) $<

.mly.ml:
	$(OCAMLYACC) $<

.mly.mli:
	$(OCAMLYACC) $<

# Clean up

clean:
	rm -f *.cm[iox]
	rm -f *~
	rm -f $(EXECUTABLES)

ultraclean:
	make clean
	rm -f lexer.ml
	rm -f parser.mli
	rm -f parser.ml
	rm -f .depend

# Dependencies

depend: lexer.ml parser.ml
	$(OCAMLDEP) $(INCLUDES) *.mli *.ml > .depend

-include .depend
